package com.toonan.core.vo;

import java.util.List;

import com.toonan.core.constant.WebplusCons;
import com.toonan.core.matatype.Dto;
import com.toonan.core.util.WebplusUtil;

/**
 * 
 * @ClassName:  PageResult   
 * @Description:分页结果类
 * @author: 陈骑元（chenqiyuan@toonan.com)
 * @date:   2022年2月13日 上午10:33:27     
 * @Copyright: 2022 www.toonan.com Inc. All rights reserved. 
 * 注意：本内容仅限于广州市图南软件有限公司内部传阅，禁止外泄以及用于其他的商业目
 */
public class PageResult {
	
	
	/**
	 * 记录总数
	 */
	private Long count;
	/**
	 * 当前页
	 */
	private Integer currentPage=1;

	/**
	 * 每页记录数
	 */
	private Integer pageSize=20;
	
	/**
	 * 总页数
	 */
	private Long totalPage;
	/**
	 * 实体类集合
	 */
	private List<?> dataList;
	public PageResult(Long count,Dto pDto) {
		super();
		Integer currentPage=Integer.parseInt(pDto.getOrDefault(WebplusCons.PAGE, WebplusCons.DEFAULT_CURRENTPAGE).toString());
		Integer pageSize=Integer.parseInt(pDto.getOrDefault(WebplusCons.LIMIT, WebplusCons.DEFAULT_PAGESIZE).toString());
		this.currentPage=currentPage;
		this.pageSize=pageSize;
		this.setCount(count);
	}
	/**
	 * 
	 * @param pDto
	 */
	public PageResult(Dto pDto) {
		super();
		Integer currentPage=Integer.parseInt(pDto.getOrDefault(WebplusCons.PAGE, WebplusCons.DEFAULT_CURRENTPAGE).toString());
		Integer pageSize=Integer.parseInt(pDto.getOrDefault(WebplusCons.LIMIT, WebplusCons.DEFAULT_PAGESIZE).toString());
		this.currentPage=currentPage;
		this.pageSize=pageSize;
	}
	public Long getCount() {
		return count;
	}

	public void setCount(Long count) {
		if(count/pageSize==0) {
			
			this.totalPage=count/pageSize;
		}else {
			this.totalPage=count/pageSize+1;
		}
		this.count = count;
	}
	public Integer getCurrentPage() {
		if(WebplusUtil.isEmpty(currentPage)) {
			currentPage=1;
		}
		return currentPage;
	}
	public void setCurrentPage(Integer currentPage) {
		this.currentPage = currentPage;
	}
	public Integer getPageSize() {
		if(WebplusUtil.isEmpty(pageSize)) {
			pageSize=1;
		}
		return pageSize;
	}
	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}
	
	public Long getTotalPage() {
		return totalPage;
	}
	public void setTotalPage(Long totalPage) {
		
		this.totalPage = totalPage;
	}
	public List<?> getDataList() {
		return dataList;
	}
	public void setDataList(List<?> dataList) {
		this.dataList = dataList;
	}

}
